﻿/*
*author:徐洪昌
*blog:http://cnblogs.com/xusir
*datetime:${Utils.GetDate} ${Utils.GetTime}
*/ 
 /*数据列表，状态审核，删除，排序*/
var ActionUrl=adminUrl+"${table.TableNameAlias}/";

#foreach($c in $ColumnList)
	#if($c.IsPrimary)
		#set ($primaryKeyAlias=$c.ColumnNameAlias)
	#set ($primaryKey=$c.ColumnName)
	#end
#end
 jQuery(function(){
      SetSelect(Enum.SwitchStatus, "SelectStatus", 1);
    LoadList();
    commonBO.initOperatePower();
 });
 /*数据列表*/
 function LoadList() {
  commonBO.initDataGrid('');
 }

/*刷新页面*/
function reload() {
    commonBO.reload();
}
/*跳转到添加页面*/
function add() {
    location.href = "saveOrUpdate"+admExtension+"?id=0";
}
/*跳转到修改页面*/
function edit() {
    location.href = "saveOrUpdate"+admExtension+"?id=" + commonBO.SelectRowData.rowData.${Utils.ToTitleLower($primaryKeyAlias)};
}
/*跳转到详细页*/
function view() {
    location.href = "view"+admExtension+"?id=" + commonBO.SelectRowData.rowData.${Utils.ToTitleLower($primaryKeyAlias)};
}
/*
 * 启用或禁用
 * */
function audit(status) {
    var dataRows = jQuery("#dataList").datagrid("getSelections");
    var ids = "";
    for (var index in dataRows) {
        if (dataRows[index].status != status)
            ids += "," + dataRows[index].${Utils.ToTitleLower($primaryKeyAlias)};
    }
    commonBO.setAudit(ids, status);
}
/*删除*/
function del() {
    var dataRows = jQuery("#dataList").datagrid("getSelections");
    var ids = "";
    for (var index in dataRows) {
        ids += "," + dataRows[index].${Utils.ToTitleLower($primaryKeyAlias)};
    }
    commonBO.delFromId(ids);
}

/*
 * 排序
 */
function sort() {
	var o = jQuery('#dataList');
	var rowcount = o.datagrid('getRows').length;
	for ( var i = 0; i < rowcount; i++) {
		var editor = o.datagrid('getEditor', {
			index : i,
			field : 'sort'
		});
		if (editor != null) {
			var row = o.datagrid('getRows')[i];
			var id = row.${Utils.ToTitleLower($primaryKeyAlias)};
			var sort = row.sort; // 修改前的排序
			var newSort = editor.target.val();
			if (sort == newSort) {
				o.datagrid('cancelEdit', i);
			} else {
				jQuery.ajax({
					url : ActionUrl + "Sort/" + id + "/" + newSort+ admExtension,
					dataType : "json",
					type : "post",
					async:false,
					success : function(result) {
						if (result.status == "SUCCESS") {
							o.datagrid('endEdit', i);
						} else {
							o.datagrid('cancelEdit', i);
						}
					}
				});
			}
		}
	}
}
